package com.evi.da.data.unmarshaller;


import com.evi.da.data.generated.Response;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.InputStream;

public class XmlResponseReader
{
	private final Unmarshaller unmarshaller;

	public XmlResponseReader()
	{
		try
		{
			final JAXBContext jaxbContext = JAXBContext.newInstance(Response.class);
			unmarshaller = jaxbContext.createUnmarshaller();
		} catch (Exception e)
		{
			throw new RuntimeException(e);
		}
	}

	public Response read(InputStream in)
	{
		try
		{
			final Response response = (Response) unmarshaller.unmarshal(in);
			return response;
		} catch (JAXBException e)
		{
			throw new RuntimeException(e);
		}
	}

}